home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 1 Vector Algebra / XMVECTOR / VectorOps.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  2.0 KB  |  58 lines

  1. /*
  2. #include <windows.h> // for XMVerifyCPUSupport
  3. #include <DirectXMath.h>
  4. #include <DirectXPackedVector.h>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace DirectX;
  8. using namespace DirectX::PackedVector;
  9.  
  10. // Overload the  "<<" operators so that we can use cout to 
  11. // output XMVECTOR objects.
  12. ostream& XM_CALLCONV operator<<(ostream& os, FXMVECTOR v)
  13. {
  14.     XMFLOAT4 dest;
  15.     XMStoreFloat4(&dest, v);
  16.  
  17.     os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
  18.     return os;
  19. }
  20.  
  21. int main()
  22. {
  23.     cout.setf(ios_base::boolalpha);
  24.  
  25.     // Check support for SSE2 (Pentium4, AMD K8, and above).
  26.     if (!XMVerifyCPUSupport())
  27.     {
  28.         cout << "directx math not supported" << endl;
  29.         return 0;
  30.     }
  31.  
  32.     XMVECTOR p = XMVectorSet(2.0f, 2.0f, 1.0f, 0.0f);
  33.     XMVECTOR q = XMVectorSet(2.0f, -0.5f, 0.5f, 0.1f);
  34.     XMVECTOR u = XMVectorSet(1.0f, 2.0f, 4.0f, 8.0f);
  35.     XMVECTOR v = XMVectorSet(-2.0f, 1.0f, -3.0f, 2.5f);
  36.     XMVECTOR w = XMVectorSet(0.0f, XM_PIDIV4, XM_PIDIV2, XM_PI);
  37.  
  38.     cout << "XMVectorAbs(v)                 = " << XMVectorAbs(v) << endl;
  39.     cout << "XMVectorCos(w)                 = " << XMVectorCos(w) << endl;
  40.     cout << "XMVectorLog(u)                 = " << XMVectorLog(u) << endl;
  41.     cout << "XMVectorExp(p)                 = " << XMVectorExp(p) << endl;
  42.  
  43.     cout << "XMVectorPow(u, p)              = " << XMVectorPow(u, p) << endl;
  44.     cout << "XMVectorSqrt(u)                = " << XMVectorSqrt(u) << endl;
  45.  
  46.     cout << "XMVectorSwizzle(u, 2, 2, 1, 3) = "
  47.         << XMVectorSwizzle(u, 2, 2, 1, 3) << endl;
  48.     cout << "XMVectorSwizzle(u, 2, 1, 0, 3) = "
  49.         << XMVectorSwizzle(u, 2, 1, 0, 3) << endl;
  50.  
  51.     cout << "XMVectorMultiply(u, v)         = " << XMVectorMultiply(u, v) << endl;
  52.     cout << "XMVectorSaturate(q)            = " << XMVectorSaturate(q) << endl;
  53.     cout << "XMVectorMin(p, v               = " << XMVectorMin(p, v) << endl;
  54.     cout << "XMVectorMax(p, v)              = " << XMVectorMax(p, v) << endl;
  55.  
  56.     return 0; 
  57. }
  58. */